'use strict';
const path = require('path');
module.exports = appInfo => {
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1539051698986_1429';

  // add your config here
  config.middleware = ['apiLogger', 'verifyToken', 'rolePermissions'];
  config.baseDir = appInfo.root;
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
      // queryName: '_csrf', // 通过 query 传递 CSRF token 的默认字段为 _csrf
      // bodyName: '_csrf', // 通过 body 传递 CSRF token 的默认字段为 _csrf
    },
    domainWhiteList: ['*']
  }
  // 允许所有请求
  config.cors = {
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
    /**
     * 客户端请求如果需要保存本地凭条（cookie），则会带有特别的请求字段 withCredentials
     * 服务端需要同样开启这个字段才能响应这些请求
     * 本质上应该是在响应头里增加了这个字段: Access-Control-Allow-Credentials: true
     */
    credentials: true,
  };

  config.customLogger = {
    scheduleLogger: {
      // consoleLevel: 'NONE',
      file: path.join(appInfo.root, 'logs', appInfo.name, 'egg-schedule.log'),
    },
  };
  config.httpclient = {
    request: {
      timeout: 10000
    }

  }
  config.redisKey = {
    activeBaseInfo: 'redis_activity_base_info', // 活动基础信息
    adminToken: 'redis_activity_admin_token', // 活动后台用户token key
    adminPermissions: 'redis_activity_admin_permissions', // 后台用户权限key
    prizeRules: 'redis_activity_nonstandard_award', // 奖品规则
    sendPrizeRequestNo: 'serial_api_no', //sendPrizeRequestNo 请求发送体验金|现金卷|体验金交易号 KEY 自增
    userChangeKey: 'redis_activity_user_change', // 用户抽奖机会key
    sendPrizeRecord: 'redis_activity_send_prize_record', // 用户抽奖记录key
    redisVirtualDataKey: 'redis_activity_virtualData' //虚拟数据公用key
  }

  config.jwtConfig = { //jsonwebtoken 配置
    cert: 'JRYIZHIPIPIXIA123456', // token 载荷
    exp: 3600 * 24, // token过期时间
  }
  // config.keys = 'wucaipipixia';
  config.salts = '&#@quanyecha?/+_-!%12345xvch,.';
  // 渠道关系秘钥
  config.combinationSalt = '#2018#jinr#888888#'
  config.alinode = { //自己的服务器
    // server:'http://192.168.28.125:7001',
    appid: '76440',
    secret: '3a0b955b7df009bba74796f011fa3ebab3ca9683',
    logdir: path.join(__dirname, '../logs')
  };
  return config;
};